var path = require("path");
var express = require("express");
var proxyMiddleware = require("http-proxy-middleware");

// // var proxyMiddleware = require('proxy-middleware');
var history = require("connect-history-api-fallback");
var app = express();
app.use(
  history({
    // 查看记录
    // verbose: true
  })
);
require("./API/config.js");
app.use(express.static(path.join(__dirname, "/dist/")));
var proxyTable = {
  // 通讯录
  "/api/org-book": {
    target: global.httpStr + global.bookIp + ":" + global.bookPort,
    changeOrigin: true
  },
  //获取地区信息
  "/api/system": {
    target: global.httpStr + global.bookIp + ":" + global.bookPort,
    changeOrigin: true
  },
  // 设置-工作台列表
  "/api/org-admin": {
    target: global.httpStr + global.bookIp + ":" + global.bookPort,
    changeOrigin: true
  },
  //企业标签
  "/api/org": {
    target: global.httpStr + global.bookIp + ":" + global.bookPort,
    changeOrigin: true
  },
  // 上传文件
  "/file": {
    target: global.httpStr + global.fileIp + ":" + global.filePort,
    changeOrigin: true
  },
  // 登陆/退出
  "/api/passport/web/user": {
    target: global.httpStr + global.loginIp + ":" + global.loginport,
    changeOrigin: true
  },

  // 公告
  "/notice": {
    target: global.httpStr + global.workIp + ":" + global.workport,
    changeOrigin: true
  },
  // 签到
  "/sign": {
    target: global.httpStr + global.workIp + ":" + global.workport,
    changeOrigin: true
  },
  // 资讯
  "/info": {
    target: global.httpStr + global.workIp + ":" + global.workport,
    changeOrigin: true
  },
  // 日志
  "/log": {
    target: global.httpStr + global.workIp + ":" + global.workport,
    changeOrigin: true
  },
  // 审批
  "/approval": {
    target: global.httpStr + global.workIp + ":" + global.workport,
    changeOrigin: true
  },

  // 导出数据-获取企业审批模型列表接口
  "/web/approval/model": {
    target: global.httpStr + "192.168.10.60:26110",
    changeOrigin: true
  },
  // 导出数据-获取企业审批模型列表接口
  "/web/approval/data": {
    target: global.httpStr + "192.168.10.60:26110",
    changeOrigin: true
  }
};

Object.keys(proxyTable).forEach(function(context) {
  var options = proxyTable[context];
  if (typeof options === "string") {
    options = {
      target: options
    };
  }
  app.use(proxyMiddleware(context, options));
});

// server.listen(port);
app.listen(1200, function(err) {
  if (err) {
    console.log(err);
    return;
  }
  console.log("server start 1200");
});
